import java.util.Scanner;

public class doWhileTest {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        // int num;
        // do {
        // System.out.println("请输入一个正整数：");
        // while (!scan.hasNextInt()) {
        // System.out.println("您输入的不是有效正整数，请重新输入：");
        // scan.next();
        // }
        // num = scan.nextInt();
        // if (num <= 0) {
        // System.out.println("您输入的不是正整数，请重新输入！");
        // }
        // } while (num <= 0);
        // System.out.println("感谢您的输入，您输入的正整数是：" + num);
        // scan.close();

        int num = (int) (Math.random() * 100 + 1);
        int guess;
        int count = 1;
        System.out.println("请输入一个数字：");
        do {
            while (!scan.hasNextInt()) {
                System.out.println("您输入的不是数字，请重新输入：");
                scan.next();
            }
            guess = scan.nextInt();
            if (guess > num) {
                System.out.println("您猜大了，请重试：");
            } else {
                System.out.println("您猜小了，请重试：");
            }
            count++;
        } while (guess != num);
        System.out.println("您猜对了，一共猜了" + count + "次");
        scan.close();
    }
}
